import { Controller, Get, Req,Post,Body,Query,UseGuards} from '@nestjs/common';
import { Request } from 'express';
import { UserService } from './user.service';
import {CreateUserDto,ListUserDto,UpdateUserDto} from './dto/index';
import {LoginGuard} from '../../../login/login.guard'
@Controller('system/user')
export class UserController {

  constructor(private userService: UserService) {}

  @UseGuards(LoginGuard)
  @Get('/find')
  find(@Query() query: ListUserDto, @Req() req){
    if(query&&query.pageNum){
      return this.userService.findPage(query,req);
    }else if(req.query.userid){
      return this.userService.findOne(req.userid);
    }else{
      return this.userService.find();
    }
    
  }


  @UseGuards(LoginGuard)
  @Post('/add')
  async add(@Body() user: CreateUserDto){
    return this.userService.add(user);
  }

  @UseGuards(LoginGuard)
  @Post('/update')
  async update(@Body() user: UpdateUserDto){
    return this.userService.update(user);
  }

  @UseGuards(LoginGuard)
  @Post('/remove')
  async remove(@Body() ids: string[]){
    return this.userService.remove(ids);
  }

  @UseGuards(LoginGuard)
  @Post('/updateStatus')
  async updateStatus(@Body() user: UpdateUserDto){    
    return this.userService.updateStatus(user.userid,user.status);
  }

  @UseGuards(LoginGuard)
  @Post('/addRole')
  async addRole(@Body("userid") userid: string,@Body("roleids") roleids: string[]){    
    return this.userService.addRole(userid,roleids);
  }
}